package model.persistence.daos;

import helpers.Utils;

import java.util.Collection;

import model.entities.Factura;
import model.entities.Local;
import model.entities.Mozo;
import model.persistence.HibernateSessionFactory;

import org.hibernate.Query;
import org.hibernate.Session;

public class FacturaDAO extends GenericDAO
{
	@SuppressWarnings("unchecked")
	public static Collection<Factura> getFacturasDelDia(Local local)
	{
		Session session = HibernateSessionFactory.getSessionFactory().openSession();
		Query query = session
				.createQuery("select f from Factura f join Local l where l.id = :idLocal and f.fecha >= :fechaHoy and f.fecha < :fechaManana");
		query.setParameter("idLocal", local.getId());
		query.setParameter("fechaHoy", Utils.getFechaHoy());
		query.setParameter("fechaManana", Utils.getFechaManana());

		return query.list();
	}

	@SuppressWarnings("unchecked")
	public static Collection<Factura> getFacturasDelDia(Mozo mozo)
	{
		Session session = HibernateSessionFactory.getSessionFactory().openSession();
		Query query = session
				.createQuery("select f from Factura f join f.mozo m where m.id = :idMozo and f.fecha >= :fechaHoy and f.fecha < :fechaManana");
		query.setParameter("idMozo", mozo.getId());
		query.setParameter("fechaHoy", Utils.getFechaHoy());
		query.setParameter("fechaManana", Utils.getFechaManana());

		return query.list();
	}
}
